package cn.yunhe.springboot_shiro.controller;

import cn.yunhe.springboot_shiro.entity.User;
import lombok.Getter;
import lombok.Setter;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@Setter
@Getter
@Controller
public class UserController {

    @RequestMapping("/login")
    public String login(User user) {
        System.out.println("进入login");
        UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword());
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        return "redirect:query";
    }
    @RequestMapping("/update")
    public String update(){
        System.out.println("进入update");
        return "update";
    }
    @RequestMapping("/query")
    public String query(){
        System.out.println("进入query");
        return "show";
    }
}
